package cz.muni.fi.pa165.ws.converter;

import cz.muni.fi.pa165.sme.api.to.SportActivityTO;
import cz.muni.fi.pa165.sportmanager.sportactivityws.SportActivity;

/**
 * @author forman
 */
public class SportActivityConverter {

	public SportActivity convert2SportActivity(final SportActivityTO sportActivityTO) {

		if (sportActivityTO == null) {
			throw new IllegalArgumentException("Cannot convert empty entity");
		}
		final SportActivity sportActivity = new SportActivity();
		sportActivity.setId(sportActivityTO.getId().toString());
		sportActivity.setSpeed(sportActivityTO.getSpeed().toString());
		sportActivity.setTitle(sportActivityTO.getTitle());
		return sportActivity;
	}

	public SportActivityTO convert2SportActivityTO(final SportActivity sportActivity) {

		if (sportActivity == null) {
			throw new IllegalArgumentException("Cannot convert empty entity");
		}

		final SportActivityTO sportActivityTO = new SportActivityTO();
		final String sourceId = sportActivity.getId();
		final String sourceSpeed = sportActivity.getSpeed();

		sportActivityTO.setId(sourceId == null ? null : Long.valueOf(sourceId));
		sportActivityTO.setSpeed(sourceSpeed == null ? null : Float.valueOf(sourceSpeed));
		sportActivityTO.setTitle(sportActivity.getTitle());
		return sportActivityTO;
	}
}
